/*
 * @Description: 
 * @Author: duan_shuangjun 丶
 * @Date: 2025-08-21 12:08:01
 * @LastEditTime: 2025-08-21 12:10:02
 */
// 在渲染进程中，通过 contextBridge 访问 ipcRenderer
// 这里我们使用 window.electronAPI 来访问 IPC 功能

// 本地数据库API接口
export interface LocalDatabaseAPI {
    // 用户相关
    userLogin(username: string, password: string): Promise<any>
    getUserById(id: number): Promise<any>
    getUserByUsername(username: string): Promise<any>
    updateUser(id: number, data: any): Promise<any>
    changePassword(id: number, oldPassword: string, newPassword: string): Promise<any>

    // 门店相关
    getShopInfo(): Promise<any>

    // 系统配置相关
    getSystemConfig(key: string): Promise<any>
    setSystemConfig(key: string, value: string, description?: string): Promise<any>
}

// 本地数据库API实现
export const localDatabaseAPI: LocalDatabaseAPI = {
    // 用户登录
    async userLogin(username: string, password: string) {
        return await (window as any).electronAPI.invoke('db:user:login', username, password)
    },

    // 根据ID获取用户信息
    async getUserById(id: number) {
        return await (window as any).electronAPI.invoke('db:user:getById', id)
    },

    // 根据用户名获取用户信息
    async getUserByUsername(username: string) {
        return await (window as any).electronAPI.invoke('db:user:getByUsername', username)
    },

    // 更新用户信息
    async updateUser(id: number, data: any) {
        return await (window as any).electronAPI.invoke('db:user:update', id, data)
    },

    // 修改密码
    async changePassword(id: number, oldPassword: string, newPassword: string) {
        return await (window as any).electronAPI.invoke('db:user:changePassword', id, oldPassword, newPassword)
    },

    // 获取门店信息
    async getShopInfo() {
        return await (window as any).electronAPI.invoke('db:shop:getInfo')
    },

    // 获取系统配置
    async getSystemConfig(key: string) {
        return await (window as any).electronAPI.invoke('db:config:get', key)
    },

    // 设置系统配置
    async setSystemConfig(key: string, value: string, description?: string) {
        return await (window as any).electronAPI.invoke('db:config:set', key, value, description)
    }
}

export default localDatabaseAPI
